import Vue from 'vue'
import moment from 'moment'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import './styles/font/iconfont.css'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
import * as directives from '@/directives'

import '@/icons' // icon
// import '@/permission' // permission control
import AMap from 'vue-amap'
import X2JS from 'x2js'
import { initKeycloak } from '@/utils/authorized' // 接入Keycloak

// for in
Object.keys(directives).forEach(key => {
  Vue.directive(key, directives[key]) // 注册自定义指令
})
Vue.use(AMap)
AMap.initAMapApiLoader({
  key: 'c081218aae02057742b9f1a100d6cf66',
  // 插件集合
  plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor']
})

Vue.prototype.moment = moment
// set ElementUI lang to EN
Vue.use(ElementUI)

Vue.prototype.$x2js = new X2JS()

Vue.config.productionTip = false
// new Vue({
//   el: '#app',
//   router,
//   store,
//   render: h => h(App)
// })

// 获取url参数
const getQueryString = function(url, name) {
  try {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = url.split('?')[1].match(reg);
    if (r != null) {
      return r[2];
    }
    return "";
  } catch (e) {
    return "";
  }
}

const renderApp = () => {
  new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
  })
}
if (/wxwork/i.test(navigator.userAgent)) {
  // 企业微信登录
  renderApp()
} else {
  // kc登录
  initKeycloak(renderApp)
}
// renderApp()

